﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Text;
using System.Threading;
using System.Windows.Forms;
using HslCommunication.Core;

namespace HslCommunication.Controls
{
	/// <summary>
	/// 一个直立的进度条控件，满足不同的情况使用
	/// </summary>
	// Token: 0x0200017A RID: 378
	public class UserVerticalProgress : UserControl
	{
		/// <summary>
		/// 实例化一个对象
		/// </summary>
		// Token: 0x06001F19 RID: 7961 RVA: 0x00097150 File Offset: 0x00095350
		public UserVerticalProgress()
		{
			this.InitializeComponent();
			this.m_borderPen = new Pen(Color.DimGray);
			this.m_backBrush = new SolidBrush(Color.Transparent);
			this.m_foreBrush = new SolidBrush(Color.Tomato);
			this.m_progressColor = Color.Tomato;
			this.m_borderColor = Color.DimGray;
			this.m_formatCenter = new StringFormat();
			this.m_formatCenter.Alignment = StringAlignment.Center;
			this.m_formatCenter.LineAlignment = StringAlignment.Center;
			this.m_UpdateAction = new Action(this.UpdateRender);
			this.hybirdLock = new SimpleHybirdLock();
			this.DoubleBuffered = true;
		}

		// Token: 0x06001F1A RID: 7962 RVA: 0x00009AA1 File Offset: 0x00007CA1
		private void UserVerticalProgress_Load(object sender, EventArgs e)
		{
		}

		// Token: 0x06001F1B RID: 7963 RVA: 0x0009723C File Offset: 0x0009543C
		private void UserVerticalProgress_Paint(object sender, PaintEventArgs e)
		{
			bool flag = !Authorization.nzugaydgwadawdibbas();
			if (!flag)
			{
				try
				{
					Graphics graphics = e.Graphics;
					Rectangle rectangle = new Rectangle(0, 0, base.Width - 1, base.Height - 1);
					graphics.FillRectangle(this.m_backBrush, rectangle);
					graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
					ProgressStyle progressStyle = this.m_progressStyle;
					ProgressStyle progressStyle2 = progressStyle;
					if (progressStyle2 != ProgressStyle.Vertical)
					{
						if (progressStyle2 == ProgressStyle.Horizontal)
						{
							int num = (int)((long)this.m_actual * (long)(base.Width - 2) / (long)this.m_Max);
							rectangle = new Rectangle(0, 0, num + 1, base.Height - 1);
							graphics.FillRectangle(this.m_foreBrush, rectangle);
						}
					}
					else
					{
						int num2 = (int)((long)this.m_actual * (long)(base.Height - 2) / (long)this.m_Max);
						rectangle = new Rectangle(0, base.Height - 1 - num2, base.Width - 1, num2);
						graphics.FillRectangle(this.m_foreBrush, rectangle);
					}
					rectangle = new Rectangle(0, 0, base.Width - 1, base.Height - 1);
					bool isTextRender = this.m_isTextRender;
					if (isTextRender)
					{
						string s = ((long)this.m_actual * 100L / (long)this.m_Max).ToString() + "%";
						using (Brush brush = new SolidBrush(this.ForeColor))
						{
							graphics.DrawString(s, this.Font, brush, rectangle, this.m_formatCenter);
						}
					}
					graphics.DrawRectangle(this.m_borderPen, rectangle);
				}
				catch (Exception)
				{
				}
			}
		}

		// Token: 0x06001F1C RID: 7964 RVA: 0x00093DEB File Offset: 0x00091FEB
		private void UserVerticalProgress_SizeChanged(object sender, EventArgs e)
		{
			base.Invalidate();
		}

		/// <summary>
		/// 获取或设置光标在控件上显示的信息
		/// </summary>
		// Token: 0x1700066D RID: 1645
		// (get) Token: 0x06001F1D RID: 7965 RVA: 0x0009740C File Offset: 0x0009560C
		// (set) Token: 0x06001F1E RID: 7966 RVA: 0x00097414 File Offset: 0x00095614
		public override Cursor Cursor
		{
			get
			{
				return base.Cursor;
			}
			set
			{
				base.Cursor = value;
			}
		}

		/// <summary>
		/// 获取或设置控件的背景颜色值
		/// </summary>
		// Token: 0x1700066E RID: 1646
		// (get) Token: 0x06001F1F RID: 7967 RVA: 0x0009741E File Offset: 0x0009561E
		// (set) Token: 0x06001F20 RID: 7968 RVA: 0x00097426 File Offset: 0x00095626
		[Description("获取或设置进度条的背景色")]
		[Category("外观")]
		[Browsable(true)]
		public override Color BackColor
		{
			get
			{
				return base.BackColor;
			}
			set
			{
				base.BackColor = value;
				Brush backBrush = this.m_backBrush;
				if (backBrush != null)
				{
					backBrush.Dispose();
				}
				this.m_backBrush = new SolidBrush(value);
				base.Invalidate();
			}
		}

		/// <summary>
		/// 获取或设置进度的颜色
		/// </summary>
		// Token: 0x1700066F RID: 1647
		// (get) Token: 0x06001F21 RID: 7969 RVA: 0x00097458 File Offset: 0x00095658
		// (set) Token: 0x06001F22 RID: 7970 RVA: 0x00097470 File Offset: 0x00095670
		[Description("获取或设置进度条的前景色")]
		[Category("外观")]
		[Browsable(true)]
		[DefaultValue(typeof(Color), "Tomato")]
		public Color ProgressColor
		{
			get
			{
				return this.m_progressColor;
			}
			set
			{
				this.m_progressColor = value;
				Brush foreBrush = this.m_foreBrush;
				if (foreBrush != null)
				{
					foreBrush.Dispose();
				}
				this.m_foreBrush = new SolidBrush(value);
				base.Invalidate();
			}
		}

		/// <summary>
		/// 进度条的最大值，默认为100
		/// </summary>
		// Token: 0x17000670 RID: 1648
		// (get) Token: 0x06001F23 RID: 7971 RVA: 0x000974A0 File Offset: 0x000956A0
		// (set) Token: 0x06001F24 RID: 7972 RVA: 0x000974B8 File Offset: 0x000956B8
		[Description("获取或设置进度条的最大值，默认为100")]
		[Category("外观")]
		[Browsable(true)]
		[DefaultValue(100)]
		public int Max
		{
			get
			{
				return this.m_Max;
			}
			set
			{
				bool flag = value > 1;
				if (flag)
				{
					this.m_Max = value;
				}
				bool flag2 = this.m_value > this.m_Max;
				if (flag2)
				{
					this.m_value = this.m_Max;
				}
				base.Invalidate();
			}
		}

		/// <summary>
		/// 当前进度条的值，不能大于最大值或小于0
		/// </summary>
		// Token: 0x17000671 RID: 1649
		// (get) Token: 0x06001F25 RID: 7973 RVA: 0x000974FC File Offset: 0x000956FC
		// (set) Token: 0x06001F26 RID: 7974 RVA: 0x00097514 File Offset: 0x00095714
		[Description("获取或设置当前进度条的值")]
		[Category("外观")]
		[Browsable(true)]
		[DefaultValue(0)]
		public int Value
		{
			get
			{
				return this.m_value;
			}
			set
			{
				bool flag = value >= 0 && value <= this.m_Max;
				if (flag)
				{
					bool flag2 = value != this.m_value;
					if (flag2)
					{
						this.m_value = value;
						bool useAnimation = this.UseAnimation;
						if (useAnimation)
						{
							int num = Interlocked.Increment(ref this.m_version);
							ThreadPool.QueueUserWorkItem(new WaitCallback(this.ThreadPoolUpdateProgress), num);
						}
						else
						{
							this.m_actual = value;
							base.Invalidate();
						}
					}
				}
			}
		}

		/// <summary>
		/// 是否显示进度
		/// </summary>
		// Token: 0x17000672 RID: 1650
		// (get) Token: 0x06001F27 RID: 7975 RVA: 0x00097598 File Offset: 0x00095798
		// (set) Token: 0x06001F28 RID: 7976 RVA: 0x000975B0 File Offset: 0x000957B0
		[Description("获取或设置是否显示进度文本")]
		[Category("外观")]
		[Browsable(true)]
		[DefaultValue(true)]
		public bool IsTextRender
		{
			get
			{
				return this.m_isTextRender;
			}
			set
			{
				this.m_isTextRender = value;
				base.Invalidate();
			}
		}

		/// <summary>
		/// 设置进度条的边框颜色
		/// </summary>
		// Token: 0x17000673 RID: 1651
		// (get) Token: 0x06001F29 RID: 7977 RVA: 0x000975C4 File Offset: 0x000957C4
		// (set) Token: 0x06001F2A RID: 7978 RVA: 0x000975DC File Offset: 0x000957DC
		[Description("获取或设置进度条的边框颜色")]
		[Category("外观")]
		[Browsable(true)]
		[DefaultValue(typeof(Color), "DimGray")]
		public Color BorderColor
		{
			get
			{
				return this.m_borderColor;
			}
			set
			{
				this.m_borderColor = value;
				Pen borderPen = this.m_borderPen;
				if (borderPen != null)
				{
					borderPen.Dispose();
				}
				this.m_borderPen = new Pen(value);
				base.Invalidate();
			}
		}

		/// <summary>
		/// 设置进度变更的速度
		/// </summary>
		// Token: 0x17000674 RID: 1652
		// (get) Token: 0x06001F2B RID: 7979 RVA: 0x0009760C File Offset: 0x0009580C
		// (set) Token: 0x06001F2C RID: 7980 RVA: 0x00097624 File Offset: 0x00095824
		[Description("获取或设置进度条的变化进度")]
		[Category("外观")]
		[Browsable(true)]
		[DefaultValue(1)]
		public int ValueChangeSpeed
		{
			get
			{
				return this.m_speed;
			}
			set
			{
				bool flag = value >= 1;
				if (flag)
				{
					this.m_speed = value;
				}
			}
		}

		/// <summary>
		/// 获取或设置进度条变化的时候是否采用动画效果
		/// </summary>
		// Token: 0x17000675 RID: 1653
		// (get) Token: 0x06001F2D RID: 7981 RVA: 0x00097648 File Offset: 0x00095848
		// (set) Token: 0x06001F2E RID: 7982 RVA: 0x00097660 File Offset: 0x00095860
		[Description("获取或设置进度条变化的时候是否采用动画效果")]
		[Category("外观")]
		[Browsable(true)]
		[DefaultValue(false)]
		public bool UseAnimation
		{
			get
			{
				return this.m_UseAnimation;
			}
			set
			{
				this.m_UseAnimation = value;
			}
		}

		/// <summary>
		/// 进度条的样式
		/// </summary>
		// Token: 0x17000676 RID: 1654
		// (get) Token: 0x06001F2F RID: 7983 RVA: 0x0009766C File Offset: 0x0009586C
		// (set) Token: 0x06001F30 RID: 7984 RVA: 0x00097684 File Offset: 0x00095884
		[Description("获取或设置进度条的样式")]
		[Category("外观")]
		[Browsable(true)]
		[DefaultValue(typeof(ProgressStyle), "Vertical")]
		public ProgressStyle ProgressStyle
		{
			get
			{
				return this.m_progressStyle;
			}
			set
			{
				this.m_progressStyle = value;
				base.Invalidate();
			}
		}

		// Token: 0x06001F31 RID: 7985 RVA: 0x00097698 File Offset: 0x00095898
		private void ThreadPoolUpdateProgress(object obj)
		{
			try
			{
				int num = (int)obj;
				bool flag = this.m_speed < 1;
				if (flag)
				{
					this.m_speed = 1;
				}
				while (this.m_actual != this.m_value)
				{
					Thread.Sleep(17);
					bool flag2 = num != this.m_version;
					if (flag2)
					{
						break;
					}
					this.hybirdLock.Enter();
					bool flag3 = this.m_actual > this.m_value;
					int actual;
					if (flag3)
					{
						int num2 = this.m_actual - this.m_value;
						bool flag4 = num2 > this.m_speed;
						if (flag4)
						{
							num2 = this.m_speed;
						}
						actual = this.m_actual - num2;
					}
					else
					{
						int num3 = this.m_value - this.m_actual;
						bool flag5 = num3 > this.m_speed;
						if (flag5)
						{
							num3 = this.m_speed;
						}
						actual = this.m_actual + num3;
					}
					this.m_actual = actual;
					this.hybirdLock.Leave();
					bool flag6 = num == this.m_version;
					if (!flag6)
					{
						break;
					}
					bool isHandleCreated = base.IsHandleCreated;
					if (isHandleCreated)
					{
						base.Invoke(this.m_UpdateAction);
					}
				}
			}
			catch (Exception)
			{
			}
		}

		// Token: 0x06001F32 RID: 7986 RVA: 0x00093DEB File Offset: 0x00091FEB
		private void UpdateRender()
		{
			base.Invalidate();
		}

		/// <summary> 
		/// 清理所有正在使用的资源。
		/// </summary>
		/// <param name="disposing">如果应释放托管资源，为 true；否则为 false。</param>
		// Token: 0x06001F33 RID: 7987 RVA: 0x000977F0 File Offset: 0x000959F0
		protected override void Dispose(bool disposing)
		{
			bool flag = disposing && this.components != null;
			if (flag)
			{
				this.components.Dispose();
			}
			base.Dispose(disposing);
		}

		/// <summary> 
		/// 设计器支持所需的方法 - 不要修改
		/// 使用代码编辑器修改此方法的内容。
		/// </summary>
		// Token: 0x06001F34 RID: 7988 RVA: 0x00097828 File Offset: 0x00095A28
		private void InitializeComponent()
		{
			base.SuspendLayout();
			base.AutoScaleDimensions = new SizeF(7f, 17f);
			base.AutoScaleMode = AutoScaleMode.Font;
			this.BackColor = SystemColors.Control;
			this.Font = new Font("微软雅黑", 9f, FontStyle.Regular, GraphicsUnit.Point, 134);
			base.Margin = new Padding(3, 4, 3, 4);
			base.Name = "UserVerticalProgress";
			base.Size = new Size(44, 192);
			base.Load += this.UserVerticalProgress_Load;
			base.SizeChanged += this.UserVerticalProgress_SizeChanged;
			base.Paint += this.UserVerticalProgress_Paint;
			base.ResumeLayout(false);
		}

		// Token: 0x0400071D RID: 1821
		private int m_version = 0;

		// Token: 0x0400071E RID: 1822
		private int m_Max = 100;

		// Token: 0x0400071F RID: 1823
		private int m_value = 0;

		// Token: 0x04000720 RID: 1824
		private int m_actual = 0;

		// Token: 0x04000721 RID: 1825
		private Pen m_borderPen;

		// Token: 0x04000722 RID: 1826
		private Color m_borderColor;

		// Token: 0x04000723 RID: 1827
		private Brush m_backBrush;

		// Token: 0x04000724 RID: 1828
		private Brush m_foreBrush;

		// Token: 0x04000725 RID: 1829
		private Color m_progressColor;

		// Token: 0x04000726 RID: 1830
		private StringFormat m_formatCenter;

		// Token: 0x04000727 RID: 1831
		private bool m_isTextRender = true;

		// Token: 0x04000728 RID: 1832
		private Action m_UpdateAction;

		// Token: 0x04000729 RID: 1833
		private SimpleHybirdLock hybirdLock;

		// Token: 0x0400072A RID: 1834
		private int m_speed = 1;

		// Token: 0x0400072B RID: 1835
		private ProgressStyle m_progressStyle = ProgressStyle.Vertical;

		// Token: 0x0400072C RID: 1836
		private bool m_UseAnimation = false;

		/// <summary> 
		/// 必需的设计器变量。
		/// </summary>
		// Token: 0x0400072D RID: 1837
		private IContainer components = null;
	}
}
